package com.Util;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

/**
 * 读取配置文件
 */
@Slf4j
public class Config {

    public static int session_timeout;

    public static int use_mysql;
    public static String mysql_jdbcurl;
    public static String mysql_user;
    public static String mysql_password;

    public static int use_redis;
    public static String redis_ip;
    public static int redis_port;
    public static String OSS;
    public static String RSA_PRIVATE_KEY;
    public static String RSA_PUBLIC_KEY;
    public static String ALI_PUBLIC_KEY;
    //阿里配置
    public static String ENDPOINT;
    public static String ACCESSKEYID;
    public static String ACCESSKEYSECRET;
    //百度配置
    public static String APP_ID;
    public static String SECURITY_KEY;
    //盐值
    public static String SALT;

    //易源数据
    public static String YU_appid;
    public static String YU_secret;


    private static Config instance = new Config();
    public static Config getInsatnce(){
        return instance;
    }



    private Config(){
        log.info("Config instance create");
        ResourceBundle resourceBoudle = null;
        try {
            resourceBoudle = new PropertyResourceBundle(
                    getClass()
                            .getClassLoader()
                            .getResourceAsStream(
                                    "config.properties"));
            //this.session_timeout=Integer.parseInt(resourceBoudle.getString("session_timeout"));
            //this.use_mysql=Integer.parseInt(resourceBoudle.getString("use_mysql"));
            this.mysql_jdbcurl=resourceBoudle.getString("mysql_jdbcurl");
            this.mysql_user=resourceBoudle.getString("mysql_user");
            this.mysql_password=resourceBoudle.getString("mysql_password");
           // this.use_redis=Integer.parseInt(resourceBoudle.getString("use_redis"));
           // this.redis_ip=resourceBoudle.getString("redis_ip");
            //this.redis_port=Integer.parseInt(resourceBoudle.getString("redis_port"));
            this.OSS=resourceBoudle.getString("OSS");
           // this.RSA_PRIVATE_KEY=resourceBoudle.getString("RSA_PRIVATE_KEY");
           // this.RSA_PUBLIC_KEY=resourceBoudle.getString("RSA_PUBLIC_KEY");
           // this.ALI_PUBLIC_KEY=resourceBoudle.getString("ALI_PUBLIC_KEY");
            this.ENDPOINT=resourceBoudle.getString ( "endpoint" );
            this.ACCESSKEYID=resourceBoudle.getString ( "accessKeyId" );
            this.ACCESSKEYSECRET=resourceBoudle.getString ( "accessKeySecret" );
            this.APP_ID=resourceBoudle.getString ( "APP_ID" );
            this.SECURITY_KEY=resourceBoudle.getString ( "SECURITY_KEY" );
            this.SALT=resourceBoudle.getString ( "SALT" );
            this.YU_appid=resourceBoudle.getString ( "YU_appid" );
            this.YU_secret=resourceBoudle.getString ( "YU_secret" );
        } catch (Exception e) {
            e.printStackTrace ();
            log.error ( "读取配置文件异常" );
        }

    }

}
